package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.Chat;
import cn.wolfcode.trip.base.query.ChatQueryObject;
import cn.wolfcode.trip.base.query.UserQueryObject;
import cn.wolfcode.trip.base.service.IChatService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("chat")
public class ChatController {
    @Autowired
    private IChatService chatService;
    @Autowired
    private IUserService userService;

    //查询聊天记录
    @GetMapping
    @ResponseBody
    public Object list(ChatQueryObject qo){
        qo.setPageSize(0);//不分页
        //qo.setOrderBy("chatTime");
        return  chatService.query(qo);
    }

    //保存聊天记录
    @PostMapping
    @ResponseBody
    public Object save(Chat chat){
        JSONResult result = new JSONResult();
        chatService.save(chat);
        return result;
    }

    //查询好友列表
    @GetMapping("/friends")
    @ResponseBody
    public Object friendsList(UserQueryObject qo){
        qo.setPageSize(0);//不分页
        return  userService.query(qo);
    }
}
